home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / UI / Window.cpp < prev    next >
Encoding:
Text File  |  1996-04-22  |  66.9 KB  |  2,281 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Window.cpp
  3.  
  4.     Contains:    Implementation of class ODWindow
  5.  
  6.     Owned by:    Richard Rodseth
  7.  
  8.     Copyright:    © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>     3/15/96    VL        1302780: Added GetFacetUnderPointForDrag so
  13.                                     that we can ignore selection when we try to
  14.                                     find the facet under mouse point.
  15.         <80>    10/18/95    JBS        1288922 in ::Update, move DrawActiveBorder
  16.                                     to after EndUpdate
  17.         <79>    10/17/95    jpa        &RCR: 1292659: Catch/ignore part exceptions
  18.                                     returned from handling activate/suspend
  19.                                     events. 1289153: Don't crash if opening
  20.                                     window fails.
  21.         <78>    10/16/95    RR        #1293067 Pass shouldDispose to
  22.                                     RegisterWindow
  23.         <77>    10/10/95    DM        1277216: GM:API: Dont return ODPoint from
  24.                                     GetWindowPoint()
  25.         <76>     10/8/95    TJ        Fixes Recomended by Refball
  26.         <75>     10/3/95    TJ        Changes done by RefBall Team
  27.         <74>     9/21/95    JBS        1284283 set _fRootFrame to NULL after
  28.                                     Close-ing or Remove-ing it
  29.         <73>     9/13/95    DM        1277216 GM:API return no ODPoints nor
  30.                                     ODPolygons
  31.         <72>     9/12/95    RR        #1282498 Removed CanvasChanged call in
  32.                                     Close() and CloseAndRemove(). #1280629
  33.                                     Catch outofmemory error in ODDrawGrowIcon
  34.         <71>      9/8/95    jpa        Renumbered private err codes [1281354]
  35.         <70>      9/8/95    TÇ        1281096 FB2:Many constants in ODTypesB
  36.                                     without kOD prefix!
  37.         <69>      9/6/95    RR        #1236387 Don't draw active border in
  38.                                     background
  39.         <68>      9/1/95    RR        # 1279100/1280338 Added fIsActive. Rewrote
  40.                                     IsActive and Select
  41.         <67>     8/29/95    RR        #1267251 Pass synthesized activate events
  42.                                     to Dispatcher  #1278308 Remove THROW in
  43.                                     SetStorageUnit
  44.         <66>     8/26/95    TÇ        1274606 FB2: Patching Remarks
  45.         <65>     8/21/95    RR         #1246478 Disabled fDIrty optimization.
  46.                                     #1243157 Changed GetFacetUnderPoint
  47.                                     iteration order. #1273596 Set _fStorageUnit
  48.                                     in InitWindowForFrame
  49.         <64>     8/15/95    RR        # 1264461/1262903 Added ODDrawGrowIcon.
  50.                                     1267238 Fixed ASSERT in InitWindow. 1263706
  51.                                     Indentation.
  52.         <63>     8/12/95    TÇ        1276807 Opt./Bug: use StdTypIO routines for
  53.                                     portable streaming & smaller footprint,
  54.                                     1276806 Optimization: use kODFalse instead
  55.                                     of kODTrue in comparisons
  56.         <62>      8/3/95    RR        #1257260: Collapse B classes. Remove
  57.                                     somInit methods. Don't call IsInitialized
  58.                                     or SubclassResponsibility
  59.         <61>     7/26/95    DM        #1270320: Memory leak fixes: delete
  60.                                     rootCanvas in Close and CloseAndRemove
  61.         <60>     6/30/95    RR        1242642 BB Ref counting fixes. Hide calls
  62.                                     HideODWindow only if shown.
  63.         <59>     6/28/95    RR        1242642 BB Mostly ref counting. Acquire and
  64.                                     Release fDraft
  65.         <58>     6/25/95    TÇ        1242642 BB: Turn on ODDebug warning if
  66.                                     refcount is wrong in
  67.                                     ODRefCntObjectsomUninit.
  68.         <57>     6/23/95    JBS        1261323 Draft::CreateFrame: add isSubframe
  69.                                     param, remove isRoot
  70.         <56>     6/15/95    RR        #1241680 Don't call somFree in InitWindow
  71.         <55>      6/8/95    RR        #1257260 Collapse base classes. #1214898
  72.                                     StdTypes.r -> ODTypes.r
  73.         <54>     5/31/95    RR        #1251403 Release after AcquirePart
  74.         <53>     5/30/95    CG        #1252280 BB: PStrToIntl should not  be used
  75.                                     by OpenDoc.
  76.         <52>     5/26/95    RR        #1251403: Multithreading naming support
  77.         <51>     5/25/95    jpa        Fixed usage of ODDebug. [1253321]
  78.         <50>     5/19/95    RR        #1249981 Added (Set)ShouldDIspose #1251128
  79.                                     WARN if shouldSave is set and root frame is
  80.                                     non-persistent
  81.         <49>     5/17/95    RR        #1250135/1250137/1250143 Getters increment
  82.                                     refcount. #1248624 Error updating window
  83.                                     causes endless alerts
  84.         <48>     5/10/95    JBS        1224727 Facet hit-testing calls should take
  85.                                     point param in frame coords;1227547
  86.                                     Coordinate system for ODWindow::Update and
  87.                                     ODFacet::Update
  88.         <47>      5/2/95    RR        # 1244133 Fixed SetDefaultWindowTitles to
  89.                                     avoid extra bogus characters. Also
  90.                                     CloseAndRemove calls frame->Close if draft
  91.                                     is readonly
  92.         <46>     4/28/95    RR        1211085 Remove 5$ comments
  93.         <45>     4/14/95    TÇ        #1235279 BB: InfoUtil & StdTypIO functions
  94.                                     should take Environment* and SU* when
  95.                                     possible
  96.         <44>     4/13/95    RR        # 1216618 Added ODVolatile, use
  97.                                     ODDeleteObject
  98.         <43>      4/7/95    RR        #1216618 Added SOM_TRY etc.
  99.         <42>      4/6/95    RR        #1211085 Remove 5$ comments
  100.         <41>      4/4/95    RR        # 1220228 Use Factory methods, #1211085
  101.                                     SetSourceFrame ref counting
  102.         <40>     3/31/95    TÇ        1223505 BB: Opening and creating documents
  103.                                     on read only media.  Fixed Creation of
  104.                                     Non-persistent frames on readonly drafts.
  105.         <39>     3/22/95    RR        #1225420, 1227993 Added private
  106.                                     InitWindowForFrame
  107.                                     Removed InitWindowFromStorage
  108.                                     Modified Externalize
  109.         <38>     3/10/95    RR        # 1220199 Externalize source frame
  110.                                     properly. 1226379 Call ODNewRgn. Dispose
  111.                                     growRgn.
  112.         <37>      3/7/95    RR        # 1220929  Added fSelectionFocus #1212490
  113.                                     Added fInBackground
  114.         <36>      3/1/95    RR        #1205622 Support re-opening an open draft
  115.                                     by making ::Open a no-op if the window is
  116.                                     already open.
  117.         <35>     2/28/95    VL        1194656: Commented out extraenous AddValue.
  118.         <34>     2/24/95    jpa        Use ODNewRgn. [1220810]
  119.         <33>     2/22/95    RR        # 1220228 Use factory methods
  120.         <32>     2/20/95    TÇ        #1221861 BB: Incomplete AOCE support needs
  121.                                     to be removed from OpenDoc
  122.         <31>     2/15/95    JBS        1198600 don't release rootFrame after
  123.                                     close, private field fShouldAdjustOnOpen
  124.         <30>     2/10/95    RR        # 1218467 Refcount source frame. Remove
  125.                                     root part field, and add root part
  126.                                     parameter to CreateRootFrame
  127.         <29>     1/26/95    eeh        1214080: OpenDoc really uses kODMacIText,
  128.                                     not kODIntlText.
  129.         <28>     1/26/95    VL        #???: Use updated Storage Unit Ref API.
  130.         <27>     1/13/95    RR        Pass eventInfo to HandleEvent
  131.         <26>    12/20/94    VL        1195012: Make Storage calls be
  132.                                     marshallable.
  133.         <25>     11/1/94    RR        #1196759 Dispose of window pointer, unless
  134.                                     it's the mailer (check was wrong)
  135.         <24>     9/30/94    RR        #1183610 Add and use fIsDirty
  136.         <23>     9/29/94    eeh        #1154961: remove local def of
  137.                                     kODPropWindowMailerIsExpanded
  138.         <22>     9/29/94    RA        1189812: Mods for 68K build.
  139.         <21>     9/22/94    JBS        1188214: coordinate bias implementation
  140.         <20>     9/22/94    eeh        #1154961 'ternalize whether mailer was
  141.                                     expanded; use this info in creating root
  142.                                     facet.
  143.         <19>      9/1/94    RR        #1181184 Externalize bounds as ODRect and
  144.                                     title as IText, and use StdTypIO routines,
  145.                                     #1167957 Fixed GetProcID so that all window
  146.                                     types are correctly ternalized, #115685
  147.                                     Don't  invalidate content region when
  148.                                     resizing. Don't Erase when Updating.
  149.         <18>     8/31/94    TÇ        #1183129, #1183116, #1183119, #1183111:
  150.                                     Lots of ErrorCode cleanup.
  151.         <17>     8/29/94    RR        #1156187,1171772,1178673,1183062,1171771
  152.         <16>     8/26/94    VL        1183174: Use updated cloning APIs.
  153.         <15>     8/19/94    TÇ        #1180922 Need to Stop using obsolete types
  154.                                     (kOD ID)
  155.         <14>     8/15/94    JBS        1181138: add frameType to CreateFrame();
  156.                                     1181156: UI API Cleanup
  157.         <13>     8/15/94    TÇ        #1180922 Removed most obsolete types from
  158.                                     StdTypes.idl
  159.         <12>     8/15/94    VL        #???: Added frameType (kODNULL) parameter
  160.                                     to CreateFrame.
  161.         <11>     8/12/94    JBS        1179919: add biasCanvas param to
  162.                                     Draft::CreateFrame()
  163.         <10>     8/12/94    JBS        1179920: move fWindow from Facet to Frame
  164.          <9>     8/10/94    JBS        1179919: coordinate system bias changes
  165.          <8>      8/4/94    eeh        bug 1179054: in ODWindowIsActive check for
  166.                                     null frontwindow
  167.          <7>      8/3/94    VL        1153123: Storage to ODStor.
  168.          <6>     7/27/94    eeh        Changes necessitated by WinStat.idl changes
  169.          <5>     7/26/94    eeh        ODQDPoint->Point, no more lying to SOM
  170.          <4>     7/21/94    eeh        Rect param to FixUpMailerWindow -> Rect*
  171.          <3>      7/5/94    VL        Fixed parameters to CreateFrame.
  172.          <2>     6/28/94    RR        First conversion
  173.          <1>     6/28/94    RR        first checked in
  174.          <0>     6/27/94    SV        SOMverted
  175.         <11>      4/6/94    JBS        1155477, 1155480
  176.         <10>     3/28/94    CG        1153547: Renamed XMPSessn.h to XMPSessM.h
  177.          <9>     3/25/94    JA        Added missing #include (1147588)
  178.          <8>     3/18/94    CC        Include ConstDef.h to access kXMPAppleTEXT.
  179.                                     (1151636)
  180.          <7>     3/16/94    eeh        bug #1149649: InitWindowFromStorage now
  181.                                     calls MakeWindowIntoReply
  182.          <6>      3/9/94    eeh        bug #1146749: assign TRUE to isMailerAware
  183.                                     by default for root windows
  184.          <5>     2/22/94    RR        #1145944 Call Release() as the last thing
  185.                                     in CloseAndRemove().
  186.          <4>     2/22/94    VL        Release Window after fRootFrame is
  187.                                     released.
  188.          <3>     2/17/94    JBS        #114???? fix inconsistent facet coords
  189.          <2>     2/16/94    JA        Include new AltPoint.h.
  190.         <91>      2/7/94    NP        Tiger Team doings.
  191.         <90>      2/7/94    NP        Tiger Team doings.
  192.         <89>      2/7/94    JA        Utility.h --> XMPUtils.h
  193.         <88>      2/7/94    NP        Tiger Team doings.
  194.         <87>      2/3/94    CG        Session reorg.
  195.         <86>      2/2/94    RR        Removed calls to SetRoot
  196.         <85>      2/2/94    JBS        new AddDisplayFrame recipie
  197.         <84>      2/1/94    JA        Removed use of obsolete typedef in
  198.                                     CreateRootFrame.
  199.         <83>      2/1/94    CC        Added ShouldShowLinks(),
  200.                                     SetShouldShowLinks(), and code to read &
  201.                                     write the setting.
  202.         <82>     1/28/94    RR        macro for ASLM qd globals
  203.         <81>     1/27/94    RR        setwtitle->SetWTitle
  204.         <80>     1/26/94    RR        Call Dispatcher::InvalidateFacetUnderMouse
  205.         <79>     1/25/94    RR        Removed redundant fWindowWasVisible. Moved
  206.                                     Release from WinState::RemoveWindow to
  207.                                     ::Close. Open no longer calls Show.
  208.         <78>     1/24/94    SS        Update for new InitCanvas method
  209.         <77>     1/24/94    eeh        moved AOCEObj init to CommonInitWindow
  210.         <76>     1/21/94    RR        Added shouldSave to InitWindow
  211.         <75>     1/19/94    RR        Removed redundant methods for drawing
  212.                                     active border
  213.         <74>     1/18/94    RR        Remove const from Drag. Use IsShown rather
  214.                                     than AcquireWindowVisible
  215.         <73>     1/15/94    VL        Release fRootFrame after closing it.
  216.         <72>     1/15/94    RR        WinState.h -> WinStat.h, Dispatch.h ->
  217.                                     Disptch.h
  218.         <71>     1/14/94    RR        Added utility GetWindowPoint (Private to UI
  219.                                     subsystem)
  220.         <70>     1/13/94    eeh        integrated AOCEObj
  221.         <69>     1/12/94    RR        Added CloseAndRemove
  222.         <68>     1/11/94    eeh        made mailer menu heierarchical
  223.         <67>     1/11/94    TÇ        Init... changes
  224.         <66>     1/10/94    RR        Added SetWindowTitle
  225.         <65>    12/22/93    RR        Added Get/SetID
  226.         <64>    12/21/93    VL        Changed ODStorageUnit::GetValueSize to
  227.                                     ODStorageUnit::GetSize.
  228.         <63>    12/21/93    JBS        InitFacet changes
  229.         <62>    12/21/93    JBS        fix constructor and CreateRootFrame to
  230.                                     CreateFrame with viewType & presentation
  231.         <61>    12/20/93    VL        Made ODWindow a non-persistent object.
  232.         <60>    12/17/93    VL        Fixed warning on ULong to UChar.
  233.         <59>    12/16/93    RR        Respect IsSelected as well as IsFrozen.
  234.                                     Call DisposeDialog if it's a dialog.
  235.         <58>    12/15/93    JBS        back pointer in facet not frame
  236.         <57>    12/14/93    EL        Use text instead of Str255.
  237.         <56>    12/14/93    TÇ        InitWindow changes.  Internalize,
  238.                                     Initialize went away.
  239.         <55>     12/8/93    VL        Used new WindowState names.
  240.         <54>     12/6/93    RR        Added SuspendResume
  241.         <53>     12/2/93    RR        Fixed bug in AcquireFrameUnderPoint
  242.         <52>     12/1/93    VL        Added floating window support. Changed code
  243.                                     for Show, Hide, IsActive. Added Select and
  244.                                     Drag. Made window invisible when it is
  245.                                     first created.
  246.         <51>    11/24/93    RR        Moved CreateRootFrame to
  247.                                     InitializePersistent
  248.         <50>    11/23/93    JA        Changed <MenuBar.h> to <MenuBar.xh>.
  249.         <49>    11/18/93    JBS        use activeFrame->AcquireWindow(ev), ensure
  250.                                     fRootFrame-SetWindow(this)
  251.         <48>    11/18/93    eeh        added SetTempMailerWindow call to
  252.                                     RemoveAECEMailer
  253.         <47>    11/18/93    TÇ        call inherited::InitializePersistent()
  254.                                     ::Externalize()
  255.         <46>    11/18/93    eeh        changed Internalize, Resized and
  256.                                     CreateRootFacet to open mailer docs
  257.                                     correctly; added GetMailerOffset
  258.         <45>    11/17/93    RR        Added accessors for shouldSave
  259.         <44>    11/15/93    eeh        various tweaks to support saving and
  260.                                     opening docs with mailer attached
  261.         <43>    11/12/93    JBS        use Facets
  262.         <42>     11/1/93    VL        Used Strong References.
  263.         <41>    10/29/93    RR        EnDisableCommand -> EnableCommand
  264.         <40>    10/29/93    TÇ        changed FixUpMailerWindow to use a Str255
  265.                                     not a Str255* to pacify CFront
  266.         <39>    10/27/93    RR        AcquireFrameUnderPoint takes point in window
  267.                                     coordinates
  268.         <38>    10/27/93    eeh        added kODPropWindowHasMailer property to
  269.                                     in/externalize, changed AOCEMailerIsActive
  270.                                     to AOCEMailerIsPresent, and added call to
  271.                                     FixUpMailerWindow to allow opening mailer
  272.                                     documents.
  273.         <37>    10/25/93    RR        Use kODStr255 for window title
  274.         <36>    10/22/93    RR        GetProcID returns a short, not a long.
  275.                                     Removed unused variable
  276.         <35>    10/21/93    RR        Added floating, resizable and rootWindow
  277.                                     properties and their accessors. Implemented
  278.                                     Show and Hide. Externalize new properties.
  279.                                     Hide window in Close. Create window
  280.                                     invisible in Internalize. etc. etc.
  281.         <34>    10/20/93    eeh        fixed problems with menus on non-AOCE
  282.                                     machines
  283.         <33>    10/20/93    eeh        Changes in UpdateMailerMenus() and
  284.                                     elsewhere required by new menu stuff.
  285.         <32>    10/14/93    RR        Add source frame parameter to
  286.                                     AddDisplayFrame call
  287.         <31>    10/14/93    JA        ODShape fu: No longer returns copies from
  288.                                     GetPlatformShape. Deal w/it.
  289.         <30>    10/12/93    eeh        Made mailer property persistent, and other
  290.                                     mailer changes.
  291.         <29>     10/8/93    VL        Added Release().
  292.         <28>     10/7/93    RR        Added fRootPart and added rootPart to
  293.                                     constructor. Renamed CreateRootFrame
  294.                                     ->CreateLayout
  295.         <27>     10/7/93    eeh        Added methods for AOCE mailer support.
  296.         <26>     10/6/93    JA        Use new fixed-point XMPPoint.
  297.         <25>     10/5/93    TÇ        added #ifdef SSREMOVEWORKAROUND until
  298.                                     su-> Remove(ev,ev) is fixed
  299.         <24>     10/4/93    RR        Define persistent properties in
  300.                                     InitializePersistent, and ASSERT their
  301.                                     presence in Internalize/Externalize
  302.         <23>     10/4/93    RR        Internalize/Externalize all window
  303.                                     properties
  304.         <22>     9/30/93    TÇ        check to make sure fLayout≠NIL before
  305.                                     trying to Close() and Release() it
  306.         <21>     9/29/93    TÇ        with RCR, changed Close() to Close Layout
  307.         <20>     9/29/93    VL        Added InitializePersistent.
  308.         <18>     9/23/93    TÇ        fixed a minor bug, was deleting fLayout
  309.                                     which is now a PstObj and responsibility of Draft
  310.         <17>     9/22/93    RR        Added Open() method
  311.         <16>     9/21/93    PH        Remove fDragInfo GetDragInfo
  312.                                     De/RegisterDroppableFrame
  313.         <15>     9/17/93    JBS        change Frame::Draw() call - no canvas param
  314.         <14>     9/16/93    JA        Updated shape/transform calls.
  315.         <13>     9/10/93    RR        Copy prototype code over
  316.         <12>     9/10/93    JBS        remove fCanvas, GetCanvas(), ChangeCanvas()
  317.         <11>     8/24/93    RR        Got rid of some CFront warnings
  318.         <10>     8/19/93    RR        Temporary hacks for "Real" shell
  319.          <9>     8/11/93    TÇ        move type & property constants to StdProps
  320.                                     & StdTypes
  321.          <8>      8/4/93    SS        Field name change for new drag mgr code
  322.          <6>     7/9/93        Added some minimal implementation
  323.          <5>     7/9/93        RCR        Rename -> ODWindow
  324.          <4>     6/23/93    RCR        Deregister -> Unregister
  325.          <3>     4/29/93    RCR        Rename includes
  326.          <2>     4/26/93    RCR        Added missing Initialize/Purge
  327.          <1>     4/9/93        RCR        Initial skeleton
  328.  
  329.     To Do:
  330.     
  331.     In Progress:
  332.         
  333. */
  334.  
  335. #define ODWindow_Class_Source
  336.  
  337.  
  338.  
  339. #ifndef _ALTPOINT_
  340. #include "AltPoint.h"            // Use C++ savvy XMPPoint and XMPRect
  341. #endif
  342.  
  343.  
  344. #ifndef SOM_ODWindow_xih
  345. #define VARIABLE_MACROS
  346. #include <Window.xih>
  347. #endif
  348.  
  349. #ifndef _PLFMDEF_
  350. #include "PlfmDef.h"
  351. #endif
  352.  
  353. #ifndef _TEMPOBJ_
  354. #include <TempObj.h>
  355. #endif
  356.  
  357. #ifndef SOM_ODStorageUnit_xh
  358. #include <StorageU.xh>
  359. #endif
  360.  
  361. #ifndef SOM_ODStorageSystem_xh
  362. #include <ODStor.xh>
  363. #endif
  364.  
  365. #ifndef SOM_ODDraft_xh
  366. #include <Draft.xh>
  367. #endif
  368.  
  369. #ifndef SOM_ODDocument_xh
  370. #include <Document.xh>
  371. #endif
  372.  
  373. #ifndef SOM_ODContainer_xh
  374. #include <ODCtr.xh>
  375. #endif
  376.  
  377. #ifndef SOM_ODSession_xh
  378. #include <ODSessn.xh>
  379. #endif
  380.  
  381. #ifndef SOM_ODPart_xh
  382. #include <Part.xh>
  383. #endif
  384.  
  385. #ifndef SOM_ODDispatcher_xh
  386. #include <Disptch.xh>
  387. #endif
  388.  
  389. #ifndef SOM_ODWindowState_xh
  390. #include <WinStat.xh>
  391. #endif
  392.  
  393. #ifndef SOM_ODArbitrator_xh
  394. #include <Arbitrat.xh>
  395. #endif
  396.  
  397. #ifndef SOM_ODFrame_xh
  398. #include <Frame.xh>
  399. #endif
  400.  
  401.  
  402. #ifndef SOM_ODFacetIterator_xh
  403. #include <FacetItr.xh>
  404. #endif
  405.  
  406. #ifndef SOM_ODFacet_xh
  407. #include <Facet.xh>
  408. #endif
  409.  
  410. #ifndef SOM_ODCanvas_xh
  411. #include <Canvas.xh>
  412. #endif
  413.  
  414. #ifndef SOM_ODShape_xh
  415. #include <Shape.xh>
  416. #endif
  417.  
  418. #ifndef SOM_ODTransform_xh
  419. #include <Trnsform.xh>
  420. #endif
  421.  
  422. #ifndef _ODUTILS_
  423. #include <ODUtils.h>
  424. #endif
  425.  
  426. #ifndef SOM_Module_OpenDoc_Foci_defined
  427. #include <Foci.xh>
  428. #endif
  429.  
  430. #ifndef _STDTYPIO_
  431. #include <StdTypIO.h>
  432. #endif
  433.  
  434. #ifndef _ITEXT_
  435. #include "IText.h"
  436. #endif
  437.  
  438. #ifndef __TOOLUTILS__
  439. #include <ToolUtils.h>
  440. #endif
  441.  
  442. #ifndef __RESOURCES__
  443. #include <Resources.h>
  444. #endif
  445.  
  446. #ifndef __OSUTILS__
  447. #include <OSUtils.h>    // SysBeep etc.
  448. #endif
  449.  
  450. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  451. #include <StdTypes.xh>
  452. #endif
  453.  
  454. #ifndef SOM_Module_OpenDoc_StdProps_defined
  455. #include <StdProps.xh>
  456. #endif
  457.  
  458. #ifndef _EXCEPT_
  459. #include "Except.h"
  460. #endif
  461.  
  462. #ifndef __OCESTANDARDMAIL__
  463. #include <OCEStandardMail.h>
  464. #endif
  465.  
  466. #ifndef __OCEERRORS__
  467. #include <OCEErrors.h>
  468. #endif
  469.  
  470. #ifndef SOM_ODMenuBar_xh
  471. #include <MenuBar.xh>
  472. #endif
  473.  
  474. #ifndef SOM_Module_OpenDoc_Commands_defined
  475. #include <CmdDefs.xh>
  476. #endif
  477.  
  478. #ifndef _PASCLSTR_
  479. #include "PasclStr.h"
  480. #endif
  481.  
  482. #ifndef _CONSTDEF_
  483. #include "ConstDef.h"
  484. #endif
  485.  
  486. #ifndef __GESTALTEQU__
  487. #include <GestaltEqu.h>
  488. #endif
  489.  
  490. #ifndef __DIALOGS__
  491. #include <Dialogs.h>
  492. #endif
  493.  
  494. #ifndef _ODDEBUG_
  495. #include "ODDebug.h"
  496. #endif
  497.  
  498. #ifndef _DOCUTILS_
  499. #include <DocUtils.h>
  500. #endif
  501.  
  502. #ifndef _STORUTIL_
  503. #include <StorUtil.h>
  504. #endif
  505.  
  506. #ifndef _ISOSTR_
  507. #include "ISOStr.h"
  508. #endif
  509.  
  510. #ifndef _DSPUTILM_
  511. #include "DspUtilM.h" 
  512. #endif
  513.  
  514. #pragma segment ODWindow
  515.  
  516. #include "WindowB.cpp"    // Platform-independent methods, if any
  517.  
  518. #define ODDebugActivates 0
  519.  
  520. //==============================================================================
  521. // Constants
  522. //==============================================================================
  523.  
  524. // Check ErrorDef.idl before adding any new codes here, to make sure they're unique.
  525. const ODError kODErrInvalidPlatformWindow         = -29828;
  526. const ODError kODErrInvalidWindow                = -29827;
  527.  
  528. // TÇ: This error code was only being used in this file, and then only
  529. // for checking the _fPlatformWindow field of a window at the beginning of
  530. // methods.  It didn't seem to have anything to do with the api.
  531. // That is why I made it private to this file.
  532. // perhaps the error that should be thrown is kODErrObjectNotInitialized?
  533. // kODErrInvalidWindow falls into the same category.
  534.  
  535.  
  536. //==============================================================================
  537. // Types
  538. //==============================================================================
  539.  
  540. //=====================================================================================
  541. // ODWindow Methods
  542. //=====================================================================================
  543.  
  544.  
  545. //-------------------------------------------------------------------------------------
  546. // ODWindow: CommonInitWindow    
  547. //-------------------------------------------------------------------------------------
  548.  
  549. SOM_Scope void  SOMLINK ODWindowCommonInitWindow(ODWindow *somSelf, Environment *ev)
  550. {
  551.     ODWindowData *somThis = ODWindowGetData(somSelf);
  552.     ODWindowMethodDebug("ODWindow","CommonInitWindow");
  553.     
  554.     SOM_TRY
  555.  
  556.         _fSession = (ODSession*) _fDraft->GetDocument(ev)->GetContainer(ev)->GetStorageSystem(ev)->GetSession(ev);    
  557.         _fArbitrator = _fSession->GetArbitrator(ev);
  558.         _fSelectionFocus = _fSession->Tokenize(ev,kODSelectionFocus);
  559.     
  560.     SOM_CATCH_ALL
  561.     SOM_ENDTRY
  562. }
  563.  
  564.  
  565. //-------------------------------------------------------------------------------------
  566. // ODWindow: InitWindow                
  567. //-------------------------------------------------------------------------------------
  568.  
  569. SOM_Scope void  SOMLINK ODWindowInitWindow (ODWindow *somSelf, Environment *ev,
  570.         ODPlatformWindow    platformWindow, 
  571.         ODType                frameType,
  572.         ODBoolean            isRootWindow,
  573.         ODBoolean            isResizable,
  574.         ODBoolean            isFloating,
  575.         ODBoolean            shouldSave,
  576.         ODBoolean            shouldDispose,
  577.         ODPart*                rootPart,
  578.         ODTypeToken            viewType,
  579.         ODTypeToken            presentation,
  580.         ODFrame*            sourceFrame)
  581. {
  582.     ODWindowData *somThis = ODWindowGetData(somSelf);
  583.     ODWindowMethodDebug("ODWindow","InitWindow");
  584.  
  585.     SOM_TRY
  586.     
  587.         /* Moved from somInit. SOM itself sets fields to zero
  588.         _fPlatformWindow = kODNULL;
  589.         _fRootFacet = kODNULL;
  590.         _fSourceFrame = kODNULL;
  591.         _fSession = kODNULL;
  592.         _fIsRootWindow = kODTrue;
  593.         _fShouldSave = kODTrue;
  594.         _fIsResizable = kODFalse;
  595.         _fIsFloating = kODFalse;
  596.         _fWasVisible = kODFalse;
  597.         _fShouldShowLinks = kODFalse;
  598.         _fArbitrator = kODNULL;
  599.         
  600.         _fStorageUnit = kODNULL;
  601.         _fIsDirty = kODFalse;
  602.         _fDraft = kODNULL;
  603.         
  604.         _fShouldAdjustOnOpen = kODFalse;
  605.         _fInBackground = kODFalse;
  606.         _fIsActive = kODFalse;
  607.         _fSelectionFocus = 0;
  608.         */
  609.         _fShouldDispose    = shouldDispose;    
  610.         
  611.         somSelf->InitRefCntObject(ev);
  612.  
  613. #if ODDebug
  614.         if (shouldSave && ODISOStrEqual(frameType, kODNonPersistentFrameObject)) 
  615.             WARN("InitWindow: shouldSave is TRUE, but root frame is nonpersistent ");
  616.  
  617. #endif
  618.         
  619.         _fPlatformWindow = platformWindow;
  620.         _fIsRootWindow    = isRootWindow;
  621.         _fIsResizable    = isResizable;
  622.         _fIsFloating    = isFloating;
  623.         if (sourceFrame)
  624.             sourceFrame->Acquire(ev);
  625.         _fSourceFrame    = sourceFrame;
  626.         _fDraft            = rootPart->GetStorageUnit(ev)->GetDraft(ev);
  627.         _fDraft->Acquire(ev);
  628.         if (!HAS_WRITE_ACCESS(_fDraft->GetPermissions(ev)))
  629.         {
  630.             shouldSave = kODFalse;
  631.             frameType = kODNonPersistentFrameObject;
  632.         }
  633.     
  634.         _fShouldSave     = shouldSave;
  635.     
  636.         somSelf->CommonInitWindow(ev);
  637.         
  638.         somSelf->CreateRootFrame(ev, frameType, viewType, presentation, rootPart);
  639.     
  640.         _fIsDirty = kODTrue;
  641.         _fShouldAdjustOnOpen = kODTrue;
  642.     
  643.     SOM_CATCH_ALL
  644.     SOM_ENDTRY
  645. }
  646. //-------------------------------------------------------------------------------------
  647. // ODWindow: InitWindowForFrame                
  648. //-------------------------------------------------------------------------------------
  649.  
  650. SOM_Scope void  SOMLINK ODWindowInitWindowForFrame (ODWindow *somSelf, Environment *ev,
  651.         ODPlatformWindow    platformWindow, 
  652.         ODFrame*            frame,
  653.         ODBoolean            isRootWindow,
  654.         ODBoolean            isResizable,
  655.         ODBoolean            isFloating,
  656.         ODBoolean            shouldSave,
  657.         ODBoolean            shouldDispose,
  658.         ODFrame*            sourceFrame)
  659. {
  660.     ODWindowData *somThis = ODWindowGetData(somSelf);
  661.     ODWindowMethodDebug("ODWindow","InitWindow");
  662.     
  663.     SOM_TRY
  664.     
  665.         ASSERT(frame != kODNULL, kODErrInvalidFrame);
  666.             
  667.         /* Moved from somInit. SOM itself sets fields to zero
  668.         _fPlatformWindow = kODNULL;
  669.         _fRootFacet = kODNULL;
  670.         _fSourceFrame = kODNULL;
  671.         _fSession = kODNULL;
  672.         _fIsRootWindow = kODTrue;
  673.         _fShouldSave = kODTrue;
  674.         _fIsResizable = kODFalse;
  675.         _fIsFloating = kODFalse;
  676.         _fWasVisible = kODFalse;
  677.         _fShouldShowLinks = kODFalse;
  678.         _fArbitrator = kODNULL;
  679.         
  680.         _fStorageUnit = kODNULL;
  681.         _fIsDirty = kODFalse;
  682.         _fDraft = kODNULL;
  683.         
  684.         _fShouldAdjustOnOpen = kODFalse;
  685.         _fInBackground = kODFalse;
  686.         _fSelectionFocus = 0;
  687.         */
  688.         _fShouldDispose    = shouldDispose;    
  689.  
  690.         somSelf->InitRefCntObject(ev);
  691.  
  692. #if ODDebug
  693.         if (shouldSave && (frame->GetStorageUnit(ev) == kODNULL))
  694.             WARN("InitWindowForFrame: shouldSave is TRUE, but root frame is nonpersistent ");
  695.  
  696. #endif
  697.  
  698.         _fPlatformWindow = platformWindow;
  699.         _fIsRootWindow    = isRootWindow;
  700.         _fIsResizable    = isResizable;
  701.         _fIsFloating    = isFloating;
  702.         if (sourceFrame)
  703.             sourceFrame->Acquire(ev);
  704.         _fSourceFrame    = sourceFrame;
  705.         { 
  706.             TempODPart part = frame->AcquirePart(ev);
  707.             _fDraft            = part->GetStorageUnit(ev)->GetDraft(ev);
  708.             _fDraft->Acquire(ev);
  709.         }
  710.     
  711.         if (!HAS_WRITE_ACCESS(_fDraft->GetPermissions(ev)))
  712.             shouldSave = kODFalse;
  713.     
  714.         _fShouldSave    = shouldSave;
  715.     
  716.         somSelf->CommonInitWindow(ev);
  717.         
  718.         if (frame)
  719.         {
  720.             frame->Acquire(ev);
  721.             frame->SetWindow(ev, somSelf);
  722.         }
  723.         _fRootFrame = frame;
  724.     
  725.         _fIsDirty = kODFalse;
  726.         _fShouldAdjustOnOpen = kODFalse;
  727.         
  728.         ODStorageUnit* frameSU = frame->GetStorageUnit(ev);
  729.         if ((frameSU != kODNULL) && (_fDraft != kODNULL))
  730.         {
  731.             ODID windowPropsID = ODGetStrongSURefProp(ev, frameSU, kODPropWindowProperties, kODStrongStorageUnitRef);
  732.             if (windowPropsID != kODNULLID)
  733.             {
  734.                 _fStorageUnit = _fDraft->AcquireStorageUnit(ev, windowPropsID);
  735.             }
  736.         }
  737.  
  738.     SOM_CATCH_ALL
  739.     SOM_ENDTRY
  740. }
  741.  
  742. //-------------------------------------------------------------------------------------
  743. // ODWindow: Purge
  744. //
  745. // Description
  746. //-------------------------------------------------------------------------------------
  747.         
  748. SOM_Scope ODSize     SOMLINK ODWindowPurge(ODWindow *somSelf, Environment *ev,
  749.         ODSize size)
  750. {
  751.     ODWindowData *somThis = ODWindowGetData(somSelf);
  752.     ODWindowMethodDebug("ODWindow","Purge");
  753.     
  754.     ODSize purgeSize = 0;
  755.     
  756.     SOM_TRY
  757.     
  758.         purgeSize = parent_Purge(somSelf, ev, size);
  759.         
  760.     SOM_CATCH_ALL
  761.         WARN("Error %ld trying to purge in ODWindowPurge",ErrorCode());
  762.         SetErrorCode(kODNoError);        // Eat the exception; Purge should not 
  763.                                         // propagate it because clients function
  764.                                         // fine whether memory was purged or not.
  765.     SOM_ENDTRY
  766.  
  767.     return purgeSize;
  768. }
  769.  
  770. //-------------------------------------------------------------------------------------
  771. // ODWindow: Release
  772. //
  773. // Description
  774. //-------------------------------------------------------------------------------------
  775.         
  776. SOM_Scope void     SOMLINK ODWindowRelease(ODWindow *somSelf, Environment *ev)
  777. {
  778.     ODWindowData *somThis = ODWindowGetData(somSelf);
  779.     ODWindowMethodDebug("ODWindow","Release");
  780.     
  781.     SOM_TRY
  782.  
  783.         parent_Release(somSelf, ev); 
  784.         if (somSelf->GetRefCount(ev) == 0) 
  785.             _fSession->GetWindowState(ev)->ReleaseWindow(ev,somSelf);
  786.  
  787.     SOM_CATCH_ALL
  788.     SOM_ENDTRY
  789. }
  790.  
  791. //-------------------------------------------------------------------------------------
  792. // ODWindow: ~ODWindow                
  793. //
  794. // Description
  795. //-------------------------------------------------------------------------------------
  796.  
  797. SOM_Scope void  SOMLINK ODWindowsomUninit (ODWindow *somSelf)
  798. {
  799.     ODWindowData *somThis = ODWindowGetData(somSelf);
  800.     ODWindowMethodDebug("ODWindow","somUninit");
  801.  
  802.     Environment* ev = somGetGlobalEnvironment();
  803.     //    • Get rid of our window
  804.     if (_fPlatformWindow && _fShouldDispose)
  805.     {
  806.         if (((WindowRecord*)_fPlatformWindow)->windowKind == dialogKind)
  807.             DisposeDialog(_fPlatformWindow);
  808.         else
  809.             DisposeWindow(_fPlatformWindow);
  810.         _fPlatformWindow = kODNULL;
  811.     }
  812.     
  813.     // Storage Unit must be released before draft    
  814.     ODSafeReleaseObject(_fStorageUnit);    
  815.     ODSafeReleaseObject(_fDraft);        
  816.     ODSafeReleaseObject(_fRootFrame);    
  817.     ODSafeReleaseObject(_fSourceFrame); 
  818. }    //     SOMLINK ODWindowsomUninit
  819.  
  820. //-------------------------------------------------------------------------------------
  821. // ODWindow: GetPlatformWindow
  822. //
  823. // Description
  824. //-------------------------------------------------------------------------------------
  825.  
  826. SOM_Scope ODPlatformWindow      SOMLINK ODWindowGetPlatformWindow(ODWindow *somSelf, Environment *ev)
  827. {
  828.     ODWindowData *somThis = ODWindowGetData(somSelf);
  829.     ODWindowMethodDebug("ODWindow","GetPlatformWindow");
  830.  
  831.     return _fPlatformWindow;
  832. }
  833.  
  834. //-------------------------------------------------------------------------------------
  835. // ODWindow: AcquireSourceFrame
  836. //
  837. // Description
  838. //-------------------------------------------------------------------------------------
  839.  
  840. SOM_Scope ODFrame*     SOMLINK ODWindowAcquireSourceFrame(ODWindow *somSelf, Environment *ev) 
  841. {
  842.     ODWindowData *somThis = ODWindowGetData(somSelf);
  843.     ODWindowMethodDebug("ODWindow","AcquireSourceFrame");
  844.     
  845.     SOM_TRY
  846.     
  847.     if (_fSourceFrame)
  848.         _fSourceFrame->Acquire(ev);
  849.  
  850.      SOM_CATCH_ALL
  851.     SOM_ENDTRY
  852.     return _fSourceFrame; 
  853. }
  854.  
  855. //-------------------------------------------------------------------------------------
  856. // ODWindow: SetSourceFrame
  857. //
  858. // Description
  859. //-------------------------------------------------------------------------------------
  860.  
  861. SOM_Scope void     SOMLINK ODWindowSetSourceFrame(ODWindow *somSelf, Environment *ev, 
  862.                                                 ODFrame* frame) 
  863. {
  864.     ODWindowData *somThis = ODWindowGetData(somSelf);
  865.     ODWindowMethodDebug("ODWindow","AcquireSourceFrame");
  866.     
  867.     SOM_TRY
  868.  
  869.         if (frame)
  870.             frame->Acquire(ev);
  871.         if (_fSourceFrame)
  872.             _fSourceFrame->Release(ev);
  873.      
  874.         _fSourceFrame = frame; 
  875.     
  876.     SOM_CATCH_ALL
  877.     SOM_ENDTRY
  878. }
  879.  
  880. //-------------------------------------------------------------------------------------
  881. // ODWindow: GetRootFrame
  882. //
  883. // Description
  884. //-------------------------------------------------------------------------------------
  885.  
  886. SOM_Scope ODFrame*  SOMLINK ODWindowGetRootFrame(ODWindow *somSelf, Environment *ev) 
  887. {
  888.     ODWindowData *somThis = ODWindowGetData(somSelf);
  889.     ODWindowMethodDebug("ODWindow","GetRootFrame");
  890.  
  891.     return _fRootFrame; 
  892. }
  893.         
  894. //-------------------------------------------------------------------------------------
  895. // ODWindow: GetRootFacet
  896. //
  897. // Description
  898. //-------------------------------------------------------------------------------------
  899.  
  900. SOM_Scope ODFacet*  SOMLINK ODWindowGetRootFacet(ODWindow *somSelf, Environment *ev)
  901. {
  902.     ODWindowData *somThis = ODWindowGetData(somSelf);
  903.     ODWindowMethodDebug("ODWindow","GetRootFacet");
  904.  
  905.     return _fRootFacet;
  906. }    
  907.     
  908. //-------------------------------------------------------------------------------------
  909. // ODWindow: CreateRootFrame
  910. // PRIVATE
  911. //
  912. // Description
  913. //-------------------------------------------------------------------------------------
  914.  
  915. SOM_Scope void  SOMLINK ODWindowCreateRootFrame(ODWindow *somSelf, Environment *ev,
  916.         ODType        frameType,
  917.         ODTypeToken    viewType,
  918.         ODTypeToken    presentation,
  919.         ODPart* rootPart)
  920. {
  921.     ODWindowData *somThis = ODWindowGetData(somSelf);
  922.     ODWindowMethodDebug("ODWindow","CreateRootFrame");
  923.  
  924.     ODShape* newShape = kODNULL;ODVolatile(newShape);
  925.     
  926.     SOM_TRY
  927.     
  928.         if (_fPlatformWindow)
  929.         {
  930.             Rect frameShape = _fPlatformWindow->portRect;
  931.             
  932.             TRY
  933.     
  934.                 newShape = new ODShape; // Can't Use factory method because no frame is available yet
  935.                 THROW_IF_NULL(newShape);
  936.                 newShape->InitShape(ev);
  937.                 
  938.             CATCH_ALL
  939.                 ODDeleteObject(newShape); newShape = kODNULL; // must delete before InitShape returns
  940.                 RERAISE;
  941.             ENDTRY
  942.     
  943.             TempODShape tempShape = newShape;    // ensures it's released
  944.             
  945.             ODRect r = _fPlatformWindow->portRect;
  946.             newShape->SetRectangle(ev,&r);
  947.             _fRootFrame = _fDraft->CreateFrame(ev, frameType, (ODFrame*)kODNULL,
  948.                                         newShape, (ODCanvas*)kODNULL,
  949.                                         rootPart, viewType, presentation,
  950.                                         kODFalse,    // isSubframe
  951.                                         kODFalse);    // isOverlaid
  952.             _fRootFrame->SetWindow(ev, somSelf);
  953.         
  954.             if (rootPart && _fSourceFrame)
  955.                 rootPart->AttachSourceFrame(ev, _fRootFrame, _fSourceFrame);
  956.         }
  957.         _fIsDirty = kODTrue;
  958.  
  959.     SOM_CATCH_ALL
  960.     SOM_ENDTRY
  961. }    // CreateRootFrame()
  962.  
  963. //-------------------------------------------------------------------------------------
  964. // ODWindow: CreateRootFacet
  965. //-------------------------------------------------------------------------------------
  966.  
  967. SOM_Scope void  SOMLINK ODWindowCreateRootFacet(ODWindow *somSelf, Environment *ev)
  968. {
  969.     ODWindowData *somThis = ODWindowGetData(somSelf);
  970.     ODWindowMethodDebug("ODWindow","CreateRootFacet");
  971.  
  972.     ODShape* frameShape = kODNULL;
  973.     ODShape* clipShape = kODNULL;
  974.     
  975.     SOM_TRY
  976.     
  977.         frameShape = _fRootFrame->AcquireFrameShape(ev, kODNULL);
  978.         clipShape = frameShape->Copy(ev);
  979.         ODReleaseObject(ev, frameShape);
  980.     
  981.         ODTransform* externalTransform = _fRootFrame->CreateTransform(ev); 
  982.         
  983.         ODWindowState* windowState = _fSession->GetWindowState(ev);
  984.         ODCanvas* rootCanvas = windowState->CreateCanvas(ev, kODQuickDraw,
  985.                                 (ODPlatformCanvas) _fPlatformWindow,
  986.                                 kODTrue,        // isDynamic
  987.                                 kODFalse);        // isOffscreen
  988.     
  989.         _fRootFacet = windowState->CreateFacet(ev, _fRootFrame, clipShape, externalTransform, rootCanvas, kODNULL);
  990.         ODReleaseObject(ev, clipShape);
  991.         ODReleaseObject(ev, externalTransform);
  992.         
  993.         _fRootFrame->FacetAdded(ev,_fRootFacet);
  994.         _fIsDirty = kODTrue;
  995.         
  996.     SOM_CATCH_ALL
  997.     SOM_ENDTRY
  998. }
  999.  
  1000. //-------------------------------------------------------------------------------------
  1001. // ODWindow: AdjustWindowShape
  1002. //
  1003. // Description
  1004. //-------------------------------------------------------------------------------------
  1005.  
  1006. SOM_Scope void  SOMLINK ODWindowAdjustWindowShape (ODWindow *somSelf, Environment *ev)
  1007. {
  1008.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1009.     ODWindowMethodDebug("ODWindow","AdjustWindowShape");
  1010.     
  1011.     SOM_TRY
  1012.  
  1013.         if (_fPlatformWindow)
  1014.         {
  1015.             Rect contentRect = _fPlatformWindow->portRect;
  1016.             Rect growRect = contentRect;
  1017.             growRect.left = growRect.right - 15;
  1018.             growRect.top = growRect.bottom - 15;
  1019.             
  1020.             RgnHandle contentRgn = ODNewRgn();
  1021.             RgnHandle growRgn = ODNewRgn();
  1022.             RectRgn(contentRgn,&contentRect);
  1023.             RectRgn(growRgn,&growRect);
  1024.                     
  1025.             if (_fIsResizable)
  1026.             DiffRgn(contentRgn,growRgn,contentRgn);
  1027.             ODDisposeHandle((Handle)growRgn);
  1028.     
  1029.             SetPort(_fPlatformWindow);
  1030.             // InvalRgn(contentRgn);
  1031.                     
  1032.             ODShape* windowShape =_fRootFrame->CreateShape(ev);
  1033.             windowShape->SetPlatformShape(ev,kODQuickDraw, (ODPlatformShape)contentRgn);
  1034.     #ifdef TO_BE_DELETED
  1035.             ODTransform* xform = _fRootFacet->AcquireExternalTransform(ev);
  1036.             windowShape->InverseTransform(ev, xform);    // JBS - must transform frameShape to facet coords
  1037.             ODReleaseObject(ev, xform);
  1038.     #endif // TO_BE_DELETED
  1039.             ODShape* tempShape = kODNULL;
  1040.             tempShape = windowShape->Copy(ev);
  1041.             _fRootFacet->GetFrame(ev)->ChangeFrameShape(ev, windowShape, kODNULL);
  1042.             _fRootFacet->ChangeGeometry(ev, tempShape, kODNULL, kODNULL);
  1043.             ODReleaseObject(ev, windowShape);
  1044.             ODReleaseObject(ev, tempShape);
  1045.         }
  1046.         _fIsDirty = kODTrue;
  1047.  
  1048.     SOM_CATCH_ALL
  1049.     SOM_ENDTRY
  1050. }    // AdjustWindowShape
  1051.  
  1052.  
  1053. //-------------------------------------------------------------------------------------
  1054. // ODWindow: Open
  1055. //
  1056. // Description
  1057. //-------------------------------------------------------------------------------------
  1058.  
  1059.  
  1060. SOM_Scope void  SOMLINK ODWindowOpen (ODWindow *somSelf, Environment *ev)
  1061. {
  1062.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1063.     ODWindowMethodDebug("ODWindow","Open");
  1064.     
  1065.     SOM_TRY
  1066.  
  1067.         if (_fRootFacet == kODNULL)
  1068.         {
  1069.             somSelf->CreateRootFacet(ev);
  1070.             if ( _fShouldAdjustOnOpen )
  1071.                 somSelf->AdjustWindowShape(ev);
  1072.             _fIsDirty = kODTrue;
  1073.         }
  1074.     
  1075.     SOM_CATCH_ALL
  1076.     SOM_ENDTRY
  1077. }
  1078.  
  1079. //-------------------------------------------------------------------------------------
  1080. // ODWindow: Close
  1081. //
  1082. // Description
  1083. //-------------------------------------------------------------------------------------
  1084.  
  1085.  
  1086. SOM_Scope void  SOMLINK ODWindowClose(ODWindow *somSelf, Environment *ev)
  1087. {
  1088.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1089.     ODWindowMethodDebug("ODWindow","Close");
  1090.  
  1091.     SOM_TRY
  1092.     
  1093.         somSelf->Hide(ev);
  1094.         _fSession->GetWindowState(ev)->RemoveWindow(ev,somSelf);
  1095.     
  1096.         if ( _fRootFrame )
  1097.         {
  1098.             if ( _fRootFacet )
  1099.             {
  1100.                 _fRootFrame->FacetRemoved(ev,_fRootFacet);
  1101.                 _fSession->GetDispatcher(ev)->InvalidateFacetUnderMouse(ev);
  1102.                 
  1103.                 ODCanvas* rootCanvas = _fRootFacet->GetCanvas(ev); // DMc - new
  1104.                 ODDeleteObject(rootCanvas); // DMc - new
  1105.                 ODDeleteObject(_fRootFacet);
  1106.             }
  1107.     
  1108.             _fRootFrame->Close(ev);
  1109.             _fRootFrame = kODNULL;
  1110.         }
  1111.         
  1112.         ODReleaseObject(ev, _fSourceFrame);
  1113.         _fIsDirty = kODTrue;
  1114.         somSelf->Release(ev);
  1115.  
  1116.     SOM_CATCH_ALL
  1117.     SOM_ENDTRY
  1118.     
  1119. }    // Close()
  1120.  
  1121. //-------------------------------------------------------------------------------------
  1122. // ODWindow: CloseAndRemove
  1123. //
  1124. // Description
  1125. //-------------------------------------------------------------------------------------
  1126.  
  1127.  
  1128. SOM_Scope void  SOMLINK ODWindowCloseAndRemove(ODWindow *somSelf, Environment *ev)
  1129. {
  1130.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1131.     ODWindowMethodDebug("ODWindow","CloseAndRemove");
  1132.     
  1133.     SOM_TRY
  1134.     
  1135.         if (_fPlatformWindow)
  1136.         {
  1137.             somSelf->Hide(ev);
  1138.             _fSession->GetWindowState(ev)->RemoveWindow(ev,somSelf);
  1139.         
  1140.             if ( _fRootFrame )
  1141.             {
  1142.                 if ( _fRootFacet )
  1143.                 {
  1144.                     _fRootFrame->FacetRemoved(ev,_fRootFacet);
  1145.                     _fSession->GetDispatcher(ev)->InvalidateFacetUnderMouse(ev);
  1146.                     
  1147.                     ODCanvas* rootCanvas = _fRootFacet->GetCanvas(ev); // DMc - new
  1148.                     ODDeleteObject(rootCanvas); // DMc - new
  1149.                     ODDeleteObject(_fRootFacet);
  1150.                 }
  1151.         
  1152.                 if (!HAS_WRITE_ACCESS(_fDraft->GetPermissions(ev)))
  1153.                 {
  1154.                     _fRootFrame->Close(ev);
  1155.                     _fRootFrame = kODNULL;
  1156.                 }
  1157.                 else
  1158.                 {
  1159.                     _fRootFrame->Remove(ev);
  1160.                     _fRootFrame = kODNULL;
  1161.                 }
  1162.             }
  1163.             
  1164.             ODReleaseObject(ev, _fSourceFrame);
  1165.             somSelf->Release(ev);
  1166.             _fIsDirty = kODTrue;
  1167.         }
  1168.  
  1169.     SOM_CATCH_ALL
  1170.     SOM_ENDTRY
  1171.  
  1172. }    
  1173.  
  1174.  
  1175.  
  1176. //-------------------------------------------------------------------------------------
  1177. // ODWindow: HandleActivateEvent
  1178. //
  1179. // Description
  1180. //-------------------------------------------------------------------------------------
  1181.  
  1182. static void ODDrawGrowIcon(ODPlatformWindow window)
  1183. {
  1184.     GrafPtr    savePort;
  1185.         
  1186.     GetPort(&savePort);
  1187.     SetPort(window);
  1188.     Rect r = window->portRect;
  1189.     r.left = r.right  - 15;
  1190.     r.top  = r.bottom - 15;
  1191.     RgnHandle    oldClip = kODNULL; ODVolatile(oldClip);
  1192.     
  1193.     TRY
  1194.         oldClip = ODNewRgn();
  1195.  
  1196.         GetClip(oldClip);
  1197.         ClipRect(&r);
  1198.         DrawGrowIcon(window);
  1199.         SetClip(oldClip);
  1200.         
  1201.     CATCH_ALL
  1202.         // Don't Reraise. Since this gets called when putting up
  1203.         // the low memory alert calls DeactivateFrontWindows #1280629
  1204.     ENDTRY
  1205.         
  1206.     ODDisposeHandle((Handle)oldClip);
  1207.     SetPort(savePort);
  1208. }
  1209.  
  1210. SOM_Scope void  SOMLINK ODWindowHandleActivateEvent (ODWindow *somSelf, Environment *ev,
  1211.         ODEventData* theEvent)
  1212. {
  1213.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1214.     ODWindowMethodDebug("ODWindow","HandleActivateEvent");
  1215.  
  1216.     ODFrame* frame = kODNULL;
  1217.     ODFacetIterator* t = kODNULL; ODVolatile(t);
  1218.     
  1219.     SOM_TRY
  1220.         
  1221.         _fIsActive = (theEvent->modifiers & activeFlag == 1);
  1222.         
  1223.         t = _fRootFacet->CreateFacetIterator(ev,
  1224.                                 kODBottomUp, kODBackToFront);
  1225.         
  1226.         for (ODFacet* facet = t->First(ev); t->IsNotComplete(ev); facet = t->Next(ev))
  1227.         {
  1228.             if (facet)
  1229.             {
  1230.                 TRY{
  1231.                     frame = facet->GetFrame(ev);
  1232.                     TempODPart part = frame->AcquirePart(ev); // -- TÇ tempobj'd
  1233.                     if ((ODPart*)part)
  1234.                         part->HandleEvent(ev,theEvent, frame, facet, kODNULL);
  1235.                 }CATCH_ALL{
  1236.                     // ignore exception
  1237.                 }ENDTRY
  1238.             }
  1239.         }
  1240.         ODDeleteObject(t);
  1241.         if (somSelf->IsResizable(ev))
  1242.             ODDrawGrowIcon(_fPlatformWindow);
  1243.  
  1244.     SOM_CATCH_ALL
  1245.     
  1246.         ODDeleteObject(t);
  1247.         
  1248.     SOM_ENDTRY
  1249. }
  1250.     
  1251. //-------------------------------------------------------------------------------------
  1252. // ODWindow: HandleUpdateEvent
  1253. //
  1254. // Description
  1255. //-------------------------------------------------------------------------------------
  1256.  
  1257. SOM_Scope void  SOMLINK ODWindowHandleUpdateEvent (ODWindow *somSelf, Environment *ev,
  1258.         ODEventData* theEvent)
  1259. {
  1260.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1261.     ODWindowMethodDebug("ODWindow","HandleUpdateEvent");
  1262.  
  1263.     ODUnused(theEvent);
  1264.     
  1265.     SOM_TRY
  1266.         somSelf->Update(ev);
  1267.     SOM_CATCH_ALL
  1268.     SOM_ENDTRY
  1269. }
  1270.  
  1271. //-------------------------------------------------------------------------------------
  1272. // ODWindow: Update
  1273. //
  1274. // Description
  1275. //-------------------------------------------------------------------------------------
  1276.  
  1277. SOM_Scope void  SOMLINK ODWindowUpdate(ODWindow *somSelf, Environment *ev)
  1278. {
  1279.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1280.     ODWindowMethodDebug("ODWindow","Update");
  1281.     
  1282.     SOM_TRY
  1283.  
  1284.         if (_fPlatformWindow)
  1285.         {
  1286.                 // #1248624 Failure handling should be further improved, but this should prevent 
  1287.                 // the infinite dialog problem
  1288.             TRY    
  1289.                 GrafPtr    savePort;
  1290.         
  1291.                 GetPort(&savePort);
  1292.                 somSelf->PrepareCanvas(ev);
  1293.                 
  1294.                 TempODFrame activeFrame 
  1295.                     = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev,_fSelectionFocus);
  1296.                 BeginUpdate(_fPlatformWindow);                    // this sets up the visRgn
  1297.                 
  1298.                 if (!EmptyRgn(_fPlatformWindow->visRgn))            // draw if updating needs to be done 
  1299.                 {
  1300.                     // Let the part decide
  1301.                     // EraseRgn (_fPlatformWindow->visRgn);
  1302.                     
  1303.                     {
  1304.                         ODFacet* rootFacet = _fRootFacet;
  1305.             
  1306.                         RgnHandle updateRgn = ODNewRgn();
  1307.                         CopyRgn(_fPlatformWindow->visRgn, updateRgn);
  1308.                         TempODShape updateShape = rootFacet->CreateShape(ev);
  1309.                         updateShape->SetPlatformShape(ev,kODQuickDraw, updateRgn);
  1310.                         TempODTransform xform = rootFacet->AcquireWindowFrameTransform(ev, kODNULL);
  1311.                         updateShape->InverseTransform(ev, xform);
  1312.                         rootFacet->Update(ev, updateShape, kODNULL);
  1313.                     }
  1314.                     // • Focus back on the window so that everything gets reset
  1315.                     somSelf->PrepareCanvas(ev);
  1316.         
  1317.                     // • After everything is back in shape we need to get the grow icon drawn
  1318.                     if (somSelf->IsResizable(ev))
  1319.                         ODDrawGrowIcon(_fPlatformWindow);
  1320.                 }
  1321.                 EndUpdate(_fPlatformWindow);
  1322.                 somSelf->DrawActiveBorder(ev,activeFrame);
  1323.                 SetPort(savePort);
  1324.                 
  1325.             CATCH_ALL
  1326.                 EndUpdate(_fPlatformWindow);
  1327.             ENDTRY
  1328.         }    
  1329.         _fIsDirty = kODTrue;
  1330.     
  1331.     SOM_CATCH_ALL
  1332.     SOM_ENDTRY
  1333. }    //  SOMLINK ODWindowUpdate
  1334.  
  1335. //-------------------------------------------------------------------------------------
  1336. // ODWindow: DrawActiveBorder
  1337. //
  1338. // Description
  1339. //-------------------------------------------------------------------------------------
  1340.  
  1341. SOM_Scope void  SOMLINK ODWindowDrawActiveBorder(ODWindow *somSelf, Environment *ev, ODFrame* frame)
  1342. {
  1343.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1344.     ODWindowMethodDebug("ODWindow","DrawActiveBorder");
  1345.  
  1346. // !!! needs to draw border for all facets of active frame
  1347. // Don't draw in background. Also need to invalidate
  1348.  
  1349.     SOM_TRY
  1350.  
  1351.         if ( !_fInBackground && frame && (frame != _fRootFrame) )
  1352.         {
  1353.             frame->DrawActiveBorder(ev);
  1354.         }
  1355.         
  1356.     SOM_CATCH_ALL
  1357.     SOM_ENDTRY
  1358. }
  1359.  
  1360. //-------------------------------------------------------------------------------------
  1361. // ODWindow: PrepareCanvas
  1362. //
  1363. // Description
  1364. //-------------------------------------------------------------------------------------
  1365.  
  1366. SOM_Scope void  SOMLINK ODWindowPrepareCanvas(ODWindow *somSelf, Environment *ev)
  1367. {
  1368.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1369.     ODWindowMethodDebug("ODWindow","PrepareCanvas");
  1370.     
  1371.     SOM_TRY
  1372.  
  1373.         if (_fPlatformWindow)
  1374.         {
  1375.             SetPort (_fPlatformWindow);
  1376.             SetOrigin(0,0);
  1377.             ClipRect (&_fPlatformWindow->portRect);
  1378.         }
  1379.         else
  1380.             ClipRect (&ODQDGlobals.thePort->portRect);
  1381.  
  1382.     SOM_CATCH_ALL
  1383.     SOM_ENDTRY
  1384. }
  1385.  
  1386. //-------------------------------------------------------------------------------------
  1387. // ODWindow: IsResizable
  1388. //
  1389. // Description
  1390. //-------------------------------------------------------------------------------------
  1391.  
  1392. SOM_Scope ODBoolean  SOMLINK ODWindowIsResizable(ODWindow *somSelf, Environment *ev)
  1393. {
  1394.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1395.     ODWindowMethodDebug("ODWindow","IsResizable");
  1396.  
  1397.     return _fIsResizable;
  1398. }
  1399.  
  1400. //-------------------------------------------------------------------------------------
  1401. // ODWindow: IsFloating
  1402. //
  1403. // Description
  1404. //-------------------------------------------------------------------------------------
  1405.  
  1406. SOM_Scope ODBoolean  SOMLINK ODWindowIsFloating(ODWindow *somSelf, Environment *ev)
  1407. {
  1408.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1409.     ODWindowMethodDebug("ODWindow","IsFloating");
  1410.  
  1411.     return _fIsFloating;
  1412. }
  1413.  
  1414. //-------------------------------------------------------------------------------------
  1415. // ODWindow: IsRootWindow
  1416. //
  1417. // Description
  1418. //-------------------------------------------------------------------------------------
  1419.  
  1420. SOM_Scope ODBoolean  SOMLINK ODWindowIsRootWindow(ODWindow *somSelf, Environment *ev)
  1421. {
  1422.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1423.     ODWindowMethodDebug("ODWindow","IsRootWindow");
  1424.  
  1425.     return _fIsRootWindow;
  1426. }
  1427.  
  1428. //-------------------------------------------------------------------------------------
  1429. // ODWindow: ShouldSave
  1430. //
  1431. // Description
  1432. //-------------------------------------------------------------------------------------
  1433.  
  1434. SOM_Scope ODBoolean  SOMLINK ODWindowShouldSave(ODWindow *somSelf, Environment *ev)
  1435. {
  1436.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1437.     ODWindowMethodDebug("ODWindow","ShouldSave");
  1438.  
  1439.     return _fShouldSave;
  1440. }
  1441.  
  1442. //-------------------------------------------------------------------------------------
  1443. // ODWindow: SetShouldSave
  1444. //
  1445. // Description
  1446. //-------------------------------------------------------------------------------------
  1447.  
  1448. SOM_Scope void  SOMLINK ODWindowSetShouldSave(ODWindow *somSelf, Environment *ev,
  1449.         ODBoolean shouldSave)
  1450. {
  1451.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1452.     ODWindowMethodDebug("ODWindow","SetShouldSave");
  1453.  
  1454.     _fShouldSave = shouldSave;
  1455.     _fIsDirty = kODTrue;
  1456. }
  1457.  
  1458. //-------------------------------------------------------------------------------------
  1459. // ODWindow: ShouldShowLinks
  1460. //
  1461. // Description
  1462. //-------------------------------------------------------------------------------------
  1463.  
  1464. SOM_Scope ODBoolean  SOMLINK ODWindowShouldShowLinks(ODWindow *somSelf, Environment *ev)
  1465. {
  1466.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1467.     ODWindowMethodDebug("ODWindow","ShouldShowLinks");
  1468.  
  1469.     return _fShouldShowLinks;
  1470. }
  1471.  
  1472. //-------------------------------------------------------------------------------------
  1473. // ODWindow: SetShouldShowLinks
  1474. //
  1475. // Description
  1476. //-------------------------------------------------------------------------------------
  1477.  
  1478. SOM_Scope void  SOMLINK ODWindowSetShouldShowLinks(ODWindow *somSelf, Environment *ev,
  1479.         ODBoolean shouldShowLinks)
  1480. {
  1481.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1482.     ODWindowMethodDebug("ODWindow","SetShouldShowLinks");
  1483.  
  1484.     _fShouldShowLinks = shouldShowLinks;
  1485.     _fIsDirty = kODTrue;
  1486. }
  1487.  
  1488. //-------------------------------------------------------------------------------------
  1489. // ODWindow: ShouldDispose
  1490. //
  1491. // Description
  1492. //-------------------------------------------------------------------------------------
  1493.  
  1494. SOM_Scope ODBoolean  SOMLINK ODWindowShouldDispose(ODWindow *somSelf, Environment *ev)
  1495. {
  1496.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1497.     ODWindowMethodDebug("ODWindow","ShouldDispose");
  1498.  
  1499.     return _fShouldDispose;
  1500. }
  1501.  
  1502. //-------------------------------------------------------------------------------------
  1503. // ODWindow: GetFacetUnderPoint
  1504. //
  1505. // Description
  1506. //-------------------------------------------------------------------------------------
  1507.  
  1508. typedef enum { kODForDragEvent, kODForMouseEvent } FacetSearchConstraint;
  1509.  
  1510. ODFacet* GetFacetUnderPointInternal( Environment *ev, ODFacet* rootFacet,
  1511.         ODPoint* windowPoint, FacetSearchConstraint constraint );
  1512.  
  1513.  
  1514. //-------------------------------------------------------------------------------------
  1515. // ODWindow: GetFacetUnderPoint
  1516. //
  1517. // Description
  1518. //-------------------------------------------------------------------------------------
  1519.  
  1520. SOM_Scope ODFacet*  SOMLINK ODWindowGetFacetUnderPointForDrag(ODWindow *somSelf,
  1521.         Environment *ev, ODPoint* windowPoint)
  1522. {
  1523.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1524.     ODWindowMethodDebug("ODWindow","GetFacetUnderPointForDrag");
  1525.  
  1526.     ODFacet* foundFacet = kODNULL;
  1527.     
  1528.     SOM_TRY
  1529.         foundFacet = GetFacetUnderPointInternal( ev, _fRootFacet, windowPoint,
  1530.                 kODForDragEvent );
  1531.     SOM_ENDTRY
  1532.  
  1533.     return foundFacet;
  1534. }
  1535.  
  1536. //-------------------------------------------------------------------------------------
  1537. // ODWindow: GetFacetUnderPoint
  1538. //
  1539. // Description
  1540. //-------------------------------------------------------------------------------------
  1541.  
  1542. SOM_Scope ODFacet*  SOMLINK ODWindowGetFacetUnderPoint(ODWindow *somSelf,
  1543.         Environment *ev, ODPoint* windowPoint)
  1544. {
  1545.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1546.     ODWindowMethodDebug("ODWindow","GetFacetUnderPoint");
  1547.  
  1548.     ODFacet* foundFacet = kODNULL;
  1549.     
  1550.     SOM_TRY
  1551.         foundFacet = GetFacetUnderPointInternal( ev, _fRootFacet, windowPoint,
  1552.                 kODForMouseEvent );
  1553.     SOM_ENDTRY
  1554.  
  1555.     return foundFacet;
  1556. }
  1557.  
  1558. //-------------------------------------------------------------------------------------
  1559. // GetFacetUnderPointInternal
  1560. //
  1561. // Description
  1562. // Utility function for the two GetFacetUnderPoint methods above.
  1563. //-------------------------------------------------------------------------------------
  1564. ODFacet* GetFacetUnderPointInternal( Environment *ev, ODFacet* rootFacet,
  1565.         ODPoint* windowPoint, FacetSearchConstraint constraint )
  1566. {
  1567.     ODFacet* foundFacet = kODNULL;
  1568.     ODFacetIterator* t = kODNULL;        ODVolatile(t);
  1569.     ODPoint framePoint;
  1570.  
  1571.     SOM_TRY
  1572.         //!!! Should use frameshape containment to prune search
  1573.         t = rootFacet->CreateFacetIterator(ev,
  1574.                                 kODTopDown, kODBackToFront);
  1575.     
  1576.         for ( ODFacet* facet = t->First(ev);
  1577.                 t->IsNotComplete(ev);
  1578.                 facet = t->Next(ev) )
  1579.         {
  1580.             // get windowPoint in frame coords for hit-testing
  1581.             { TempODTransform winToFrame = facet->AcquireWindowFrameTransform(ev, kODNULL);
  1582.               framePoint = *windowPoint;
  1583.               winToFrame->InvertPoint(ev, &framePoint);
  1584.             }
  1585.             
  1586.             if (facet->ContainsPoint(ev, &framePoint, kODNULL))
  1587.             {
  1588.                 foundFacet = facet;
  1589. #if 0            /* this is the old code */
  1590.                 if (facet->GetFrame(ev)->IsFrozen(ev) || facet->IsSelected(ev))        
  1591.                     t->SkipChildren(ev);
  1592. #else            /* this is the new -- replaces above */
  1593.                 if (facet->GetFrame(ev)->IsFrozen(ev))
  1594.                     t->SkipChildren(ev);
  1595.                 else if ( (constraint == kODForMouseEvent) && facet->IsSelected(ev))
  1596.                 {
  1597.                     t->SkipChildren(ev);
  1598.                 }
  1599. #endif
  1600.             }
  1601.             else
  1602.                 t->SkipChildren(ev);
  1603.         }
  1604.         delete t;
  1605.  
  1606.     SOM_CATCH_ALL
  1607.  
  1608.         ODDeleteObject(t);
  1609.  
  1610.     SOM_ENDTRY
  1611.  
  1612.     return foundFacet;
  1613. }
  1614.  
  1615. //-------------------------------------------------------------------------------------
  1616. // ODWindow: IsActive
  1617. //
  1618. // Description
  1619. //-------------------------------------------------------------------------------------
  1620.  
  1621. SOM_Scope ODBoolean  SOMLINK ODWindowIsActive(ODWindow *somSelf, Environment *ev)
  1622. {
  1623.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1624.     ODWindowMethodDebug("ODWindow","IsActive");
  1625.     
  1626.     ODBoolean isActive = _fIsActive && !_fInBackground;
  1627.  
  1628.     return isActive;
  1629. }
  1630.  
  1631. //-------------------------------------------------------------------------------------
  1632. // ODWindow: Show
  1633. //
  1634. // Description
  1635. //-------------------------------------------------------------------------------------
  1636.  
  1637. SOM_Scope void  SOMLINK ODWindowShow(ODWindow *somSelf, Environment *ev)
  1638. {
  1639.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1640.     ODWindowMethodDebug("ODWindow","Show");
  1641.     
  1642.     SOM_TRY
  1643.  
  1644.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1645.         
  1646.         if (!somSelf->IsShown(ev))    
  1647.             _fSession->GetWindowState(ev)->ShowODWindow(ev,somSelf);
  1648.         _fIsDirty = kODTrue;
  1649.  
  1650.     SOM_CATCH_ALL
  1651.     SOM_ENDTRY
  1652. }
  1653.     
  1654. //-------------------------------------------------------------------------------------
  1655. // ODWindow: Hide
  1656. //
  1657. // Description
  1658. //-------------------------------------------------------------------------------------
  1659.  
  1660. SOM_Scope void  SOMLINK ODWindowHide(ODWindow *somSelf, Environment *ev)
  1661. {
  1662.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1663.     ODWindowMethodDebug("ODWindow","Hide");
  1664.  
  1665.     SOM_TRY
  1666.  
  1667.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1668.  
  1669.         if (somSelf->IsShown(ev))
  1670.         {
  1671.             _fSession->GetWindowState(ev)->HideODWindow(ev,somSelf);
  1672.             _fIsDirty = kODTrue;
  1673.         }
  1674.  
  1675.     SOM_CATCH_ALL
  1676.     SOM_ENDTRY
  1677. }
  1678.  
  1679. //-------------------------------------------------------------------------------------
  1680. // ODWindow: SuspendResume
  1681. //
  1682. // Send event to each visible window
  1683. //-------------------------------------------------------------------------------------
  1684.  
  1685. SOM_Scope void  SOMLINK ODWindowSuspendResume(ODWindow *somSelf, Environment *ev,
  1686.         ODEventData* event)
  1687. {
  1688.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1689.     ODWindowMethodDebug("ODWindow","SuspendResume");
  1690.  
  1691.  
  1692.     const short kResumeMask = 0x01;    // High byte suspend/resume event 
  1693.     ODFrame* frame = kODNULL;
  1694.     ODFacetIterator* t = kODNULL; ODVolatile(t);
  1695.  
  1696.     _fInBackground = (event->message & kResumeMask) == 0;
  1697.  
  1698.     SOM_TRY
  1699.  
  1700.         somSelf->PrepareCanvas(ev);
  1701.         if (somSelf->IsResizable(ev))
  1702.             ODDrawGrowIcon(_fPlatformWindow);
  1703.     
  1704.         t = _fRootFacet->CreateFacetIterator(ev,
  1705.                                 kODTopDown, kODFrontToBack);
  1706.         
  1707.         for (ODFacet* facet = t->First(ev); t->IsNotComplete(ev); facet = t->Next(ev))
  1708.         {
  1709.             if (facet)
  1710.             {
  1711.                 TRY{
  1712.                     frame = facet->GetFrame(ev);
  1713.                     TempODPart part = frame->AcquirePart(ev); // -- TÇ tempobj'd
  1714.                     if ((ODPart*)part)
  1715.                         part->HandleEvent(ev,event, frame, facet, kODNULL);
  1716.                 }CATCH_ALL{
  1717.                     // ignore exception
  1718.                 }ENDTRY
  1719.             }
  1720.         }
  1721.         ODDeleteObject(t);
  1722.  
  1723.         
  1724.         TempODFrame activeFrame = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev,_fSelectionFocus);
  1725.         if (activeFrame)
  1726.         {
  1727.             if (_fInBackground)
  1728.                 activeFrame->InvalidateActiveBorder(ev);
  1729.             else    // Limitation of API: Can't call Invalidate twice, because shape gets released
  1730.                 activeFrame->DrawActiveBorder(ev);
  1731.         }
  1732.         
  1733.  
  1734.  
  1735.     SOM_CATCH_ALL
  1736.     
  1737.         ODDeleteObject(t);
  1738.         
  1739.     SOM_ENDTRY
  1740. }
  1741.  
  1742. //-------------------------------------------------------------------------------------
  1743. // ODWindow: Activate
  1744. //
  1745. // Description
  1746. //-------------------------------------------------------------------------------------
  1747.  
  1748. SOM_Scope void  SOMLINK ODWindowActivate(ODWindow *somSelf, Environment *ev)
  1749. {
  1750.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1751.     ODWindowMethodDebug("ODWindow","Activate");
  1752.  
  1753.     SOM_TRY
  1754.     
  1755.         // Floating window implementation relies on suppressing activate events
  1756.         // Part::HandleEvent expects them, so they're synthesize here.
  1757.         // They must be routed through the dispatcher, so they can be monitored/patched
  1758.         // The modifiers field is hacked to alert the dispatcher that this is
  1759.         // an OpenDoc-generated activate event.
  1760.     
  1761.         EventRecord event;
  1762.  
  1763.         SetActivateEvent(event, _fPlatformWindow, kODTrue);
  1764.                 
  1765.         _fSession->GetDispatcher(ev)->Dispatch(ev, &event);
  1766.  
  1767.     SOM_CATCH_ALL
  1768.     SOM_ENDTRY
  1769. }
  1770.  
  1771. //-------------------------------------------------------------------------------------
  1772. // ODWindow: Deactivate
  1773. //
  1774. // Description
  1775. //-------------------------------------------------------------------------------------
  1776.  
  1777. SOM_Scope void  SOMLINK ODWindowDeactivate(ODWindow *somSelf, Environment *ev)
  1778. {
  1779.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1780.     ODWindowMethodDebug("ODWindow","Deactivate");
  1781.  
  1782.     SOM_TRY
  1783.     
  1784.         // Floating window implementation relies on suppressing activate events
  1785.         // Part::HandleEvent expects them, so they're synthesize here.
  1786.         // They must be routed through the dispatcher, so they can be monitored/patched
  1787.         // Bit 1 (starting from 0) of the modifiers field is set to alert the dispatcher 
  1788.         // that this is an OpenDoc-generated activate event.
  1789.  
  1790.         EventRecord event;
  1791.         
  1792.         SetActivateEvent(event, _fPlatformWindow, kODFalse);
  1793.                 
  1794.         _fSession->GetDispatcher(ev)->Dispatch(ev, &event);
  1795.  
  1796.     SOM_CATCH_ALL
  1797.     SOM_ENDTRY
  1798. }
  1799.  
  1800. //-------------------------------------------------------------------------------------
  1801. // ODWindow: Drag
  1802. //
  1803. // Description
  1804. //-------------------------------------------------------------------------------------
  1805.  
  1806. SOM_Scope void  SOMLINK ODWindowDrag(ODWindow *somSelf, Environment *ev,
  1807.         Point* startPoint,
  1808.         Rect* draggingBounds)
  1809. {
  1810.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1811.     ODWindowMethodDebug("ODWindow","Drag");
  1812.  
  1813.     SOM_TRY
  1814.  
  1815.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1816.         
  1817.         _fSession->GetWindowState(ev)->DragODWindow(ev,somSelf, startPoint, draggingBounds);
  1818.  
  1819.     SOM_CATCH_ALL
  1820.     SOM_ENDTRY
  1821. }
  1822.  
  1823. //-------------------------------------------------------------------------------------
  1824. // ODWindow: Select
  1825. //
  1826. // Description
  1827. //-------------------------------------------------------------------------------------
  1828.  
  1829. SOM_Scope void  SOMLINK ODWindowSelect(ODWindow *somSelf, Environment *ev)
  1830. {
  1831.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1832.     ODWindowMethodDebug("ODWindow","Select");
  1833.  
  1834.     SOM_TRY
  1835.  
  1836.         if (_fInBackground)
  1837.         {
  1838.             ProcessSerialNumber current;
  1839.             OSErr    err = GetCurrentProcess(¤t);
  1840.             if (err == noErr)
  1841.                 SetFrontProcess(¤t);
  1842.         }    
  1843.         _fSession->GetWindowState(ev)->SelectODWindow(ev,somSelf);
  1844.  
  1845.     SOM_CATCH_ALL
  1846.     SOM_ENDTRY
  1847. }
  1848.  
  1849. //-------------------------------------------------------------------------------------
  1850. // ODWindow: IsShown
  1851. //
  1852. // Description
  1853. //-------------------------------------------------------------------------------------
  1854.  
  1855. SOM_Scope ODBoolean  SOMLINK ODWindowIsShown(ODWindow *somSelf, Environment *ev)
  1856. {
  1857.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1858.     ODWindowMethodDebug("ODWindow","IsShown");
  1859.     
  1860.     ODBoolean isShown = kODFalse;
  1861.     
  1862.     SOM_TRY
  1863.  
  1864.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1865.         
  1866.         isShown = ((WindowRecord*)_fPlatformWindow)->visible;
  1867.  
  1868.     SOM_CATCH_ALL
  1869.     SOM_ENDTRY
  1870.     
  1871.     return isShown;
  1872. }
  1873.  
  1874. //-------------------------------------------------------------------------------------
  1875. // Protected methods
  1876. //
  1877. // Description
  1878. //-------------------------------------------------------------------------------------
  1879.  
  1880. SOM_Scope ODBoolean  SOMLINK ODWindowHasCloseBox(ODWindow *somSelf, Environment *ev)
  1881. {
  1882.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1883.     ODWindowMethodDebug("ODWindow","HasCloseBox");
  1884.  
  1885.     ODBoolean hasCloseBox = kODFalse;
  1886.     
  1887.     SOM_TRY
  1888.  
  1889.         ASSERT(_fPlatformWindow != kODNULL,kODErrInvalidPlatformWindow);
  1890.         hasCloseBox =     ((WindowRecord*)_fPlatformWindow)->goAwayFlag;
  1891.  
  1892.     SOM_CATCH_ALL
  1893.     SOM_ENDTRY
  1894.     
  1895.     return hasCloseBox;
  1896. }
  1897.     
  1898. SOM_Scope ODBoolean  SOMLINK ODWindowHasZoomBox(ODWindow *somSelf, Environment *ev)
  1899.  
  1900. {
  1901.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1902.     ODWindowMethodDebug("ODWindow","HasZoomBox");
  1903.  
  1904.     ODBoolean hasZoomBox = kODFalse;
  1905.     
  1906.     SOM_TRY
  1907.     
  1908.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1909.         hasZoomBox = ((WindowRecord*)_fPlatformWindow)->spareFlag;
  1910.  
  1911.     SOM_CATCH_ALL
  1912.     SOM_ENDTRY
  1913.     
  1914.     return hasZoomBox;
  1915. }
  1916.  
  1917. SOM_Scope ODBoolean  SOMLINK ODWindowHasGrowBox(ODWindow *somSelf, Environment *ev)
  1918. {
  1919.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1920.     ODWindowMethodDebug("ODWindow","HasGrowBox");
  1921.  
  1922.     ODBoolean hasGrowBox = kODFalse;
  1923.     
  1924.     SOM_TRY
  1925.  
  1926.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1927.         hasGrowBox = somSelf->IsResizable(ev); 
  1928.  
  1929.     SOM_CATCH_ALL
  1930.     SOM_ENDTRY
  1931.     
  1932.     return hasGrowBox;
  1933. }
  1934.  
  1935. SOM_Scope ODSShort  SOMLINK ODWindowGetProcID(ODWindow *somSelf, Environment *ev)
  1936. {
  1937.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1938.     ODWindowMethodDebug("ODWindow","GetProcID");
  1939.     
  1940.     short theID = 0; 
  1941.     ResType theType;
  1942.     Str255 theName;
  1943.  
  1944.     SOM_TRY
  1945.     
  1946.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1947.  
  1948.         GetResInfo(((WindowPeek)_fPlatformWindow)->windowDefProc, &theID, &theType, theName);
  1949.         short theVariant = GetWVariant(_fPlatformWindow);
  1950.         theID = theID*16 + theVariant;
  1951.         // return GetWVariant(_fPlatformWindow);
  1952.         
  1953.     SOM_CATCH_ALL
  1954.     SOM_ENDTRY
  1955.     
  1956.     return theID;
  1957.     
  1958. }
  1959.  
  1960. SOM_Scope void  SOMLINK ODWindowGetWindowBounds(ODWindow *somSelf, Environment *ev,
  1961.         Rect* bounds)
  1962. {
  1963.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1964.     ODWindowMethodDebug("ODWindow","GetWindowBounds");
  1965.     
  1966.     SOM_TRY
  1967.  
  1968.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1969.         
  1970.         ODRgnHandle contRgn;
  1971.         
  1972.         contRgn = ((WindowRecord*)_fPlatformWindow)->contRgn;
  1973.         *bounds = (**contRgn).rgnBBox;
  1974.         
  1975.     SOM_CATCH_ALL
  1976.     SOM_ENDTRY    
  1977. }
  1978.  
  1979. SOM_Scope ODSLong  SOMLINK ODWindowGetRefCon(ODWindow *somSelf, Environment *ev)
  1980. {
  1981.     ODWindowData *somThis = ODWindowGetData(somSelf);
  1982.     ODWindowMethodDebug("ODWindow","GetRefCon");
  1983.     
  1984.     ODSLong refCon = 0;
  1985.     
  1986.     SOM_TRY
  1987.  
  1988.         ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
  1989.         refCon = ((WindowRecord*)_fPlatformWindow)->refCon;
  1990.  
  1991.     SOM_CATCH_ALL
  1992.     SOM_ENDTRY    
  1993.     
  1994.     return refCon;
  1995. }
  1996.  
  1997. //-------------------------------------------------------------------------------------
  1998. // ODWindow: SetWindowTitle
  1999. //
  2000. // Description
  2001. //-------------------------------------------------------------------------------------
  2002.  
  2003. SOM_Scope void  SOMLINK ODWindowSetWindowTitle(ODWindow *somSelf, Environment *ev,
  2004.         char* title)
  2005. {
  2006.     ODWindowData *somThis = ODWindowGetData(somSelf);
  2007.     ODWindowMethodDebug("ODWindow","SetWindowTitle");
  2008.     
  2009.     Str255 titleCopy;
  2010.     
  2011.     strcpy( (char*) &(titleCopy[1]), title);
  2012.     titleCopy[0] = strlen(title);
  2013.     
  2014.     SOM_TRY
  2015.  
  2016.         SetWTitle(_fPlatformWindow, titleCopy);
  2017.         _fIsDirty = kODTrue;
  2018.  
  2019.     SOM_CATCH_ALL
  2020.     SOM_ENDTRY    
  2021. }
  2022.  
  2023. //-------------------------------------------------------------------------------------
  2024. // ODWindow: SetWasVisible
  2025. //
  2026. // Description
  2027. //-------------------------------------------------------------------------------------
  2028.  
  2029. SOM_Scope void  SOMLINK ODWindowSetWasVisible(ODWindow *somSelf, Environment *ev,
  2030.         ODBoolean wasVisible)
  2031. {
  2032.     ODWindowData *somThis = ODWindowGetData(somSelf);
  2033.     ODWindowMethodDebug("ODWindow","SetWasVisible");
  2034.  
  2035.     _fWasVisible = wasVisible;
  2036.     _fIsDirty = kODTrue;
  2037. }
  2038.  
  2039. //-------------------------------------------------------------------------------------
  2040. // ODWindow: GetWasVisible
  2041. //
  2042. // Description
  2043. //-------------------------------------------------------------------------------------
  2044.  
  2045. SOM_Scope ODBoolean  SOMLINK ODWindowGetWasVisible(ODWindow *somSelf, Environment *ev)
  2046. {
  2047.     ODWindowData *somThis = ODWindowGetData(somSelf);
  2048.     ODWindowMethodDebug("ODWindow","GetWasVisible");
  2049.  
  2050.     return _fWasVisible;
  2051. }
  2052.  
  2053. //-------------------------------------------------------------------------------------
  2054. // ODWindow: Externalize
  2055. //
  2056. // Description
  2057. //-------------------------------------------------------------------------------------
  2058.  
  2059. SOM_Scope void  SOMLINK ODWindowExternalize(ODWindow *somSelf, Environment *ev)
  2060. {
  2061.     ODWindowData *somThis = ODWindowGetData(somSelf);
  2062.     ODWindowMethodDebug("ODWindow","Externalize");
  2063.  
  2064.     // #1246478 Removing fIsDirty optimization, because clients can call GetPlatformWindow
  2065.     // and change things. 
  2066.     //if ( !_fIsDirty )
  2067.     //    return;
  2068.         
  2069.     SOM_TRY
  2070.  
  2071.     // Should Title be an ODIText?
  2072.         
  2073.         ODStorageUnit* su = _fStorageUnit;
  2074.         
  2075.         // No need to do these ASSERTs because the StdTypIO routines make sure
  2076.         // the appropriate property and value exist. -TÇ
  2077.         /*
  2078.         ASSERT(su->Exists(ev,kODPropWindowRect, kODRect, 0), kODErrInvalidWindow);        
  2079.         ASSERT(su->Exists(ev,kODPropWindowTitle, kODMacIText, 0), kODErrInvalidWindow);
  2080.         ASSERT(su->Exists(ev,kODPropWindowProcID, kODSShort, 0), kODErrInvalidWindow);
  2081.         ASSERT(su->Exists(ev,kODPropWindowIsVisible, kODBoolean, 0), kODErrInvalidWindow);
  2082.         ASSERT(su->Exists(ev,kODPropWindowHasCloseBox, kODBoolean, 0), kODErrInvalidWindow);
  2083.         ASSERT(su->Exists(ev,kODPropWindowHasZoomBox, kODBoolean, 0), kODErrInvalidWindow);
  2084.         ASSERT(su->Exists(ev,kODPropWindowIsResizable, kODBoolean, 0), kODErrInvalidWindow);
  2085.         ASSERT(su->Exists(ev,kODPropWindowIsRootWindow, kODBoolean, 0), kODErrInvalidWindow);
  2086.         ASSERT(su->Exists(ev,kODPropWindowIsFloating, kODBoolean, 0), kODErrInvalidWindow);
  2087.         ASSERT(su->Exists(ev,kODPropWindowRefCon, kODSLong, 0), kODErrInvalidWindow);
  2088.         ASSERT(su->Exists(ev,kODPropRootFrame, kODStrongStorageUnitRef, 0), kODErrInvalidWindow);
  2089.         //ASSERT(su->Exists(ev,kODPropSourceFrame, kODStrongStorageUnitRef, 0), kODErrInvalidWindow);
  2090.         ASSERT(su->Exists(ev,kODPropShouldShowLinks, kODBoolean, 0), kODErrInvalidWindow);
  2091.         */
  2092.         
  2093.         // Externalize Window Manager properties
  2094.     
  2095.         // Externalize the bounds as a standard ODRect
  2096.     
  2097.         Rect r;
  2098.         somSelf->GetWindowBounds(ev,&r);
  2099.         ODRect odRect(r);
  2100.         ODSetRectProp(ev, su, kODPropWindowRect, kODRect, &odRect);
  2101.         
  2102.         // Externalize title as an IText
  2103.         
  2104.         Str255 title;
  2105.         GetWTitle(_fPlatformWindow, title);
  2106.         
  2107.         ODScriptCode script = FontToScript(GetAppFont());
  2108.         ODLangCode lang = GetScriptVariable(script, smScriptLang);
  2109.  
  2110.         ODIText* iText = CreateITextPString(script, lang, &title[0]);
  2111.         ODSetITextProp(ev, su, kODPropWindowTitle, kODMacIText, iText);
  2112.         DisposeIText(iText);
  2113.     
  2114.         ODSetSShortProp(ev, su, kODPropWindowProcID, kODSShort, somSelf->GetProcID(ev));
  2115.         ODSetBooleanProp(ev, su, kODPropWindowIsVisible, kODBoolean, somSelf->IsShown(ev));
  2116.         ODSetBooleanProp(ev, su, kODPropWindowHasCloseBox, kODBoolean,  somSelf->HasCloseBox(ev));
  2117.         ODSetBooleanProp(ev, su, kODPropWindowHasZoomBox, kODBoolean,  somSelf->HasZoomBox(ev));
  2118.         ODSetULongProp(ev, su, kODPropWindowRefCon, kODSLong, somSelf->GetRefCon(ev));
  2119.         
  2120.         // Other properties
  2121.         
  2122.         ODSetBooleanProp(ev, su, kODPropWindowIsResizable, kODBoolean,   somSelf->IsResizable(ev));
  2123.         ODSetBooleanProp(ev, su, kODPropWindowIsFloating, kODBoolean, somSelf->IsFloating(ev));
  2124.         ODSetBooleanProp(ev, su, kODPropWindowIsRootWindow, kODBoolean, somSelf->IsRootWindow(ev));
  2125.     
  2126.         ODSetBooleanProp(ev, su, kODPropShouldShowLinks, kODBoolean, somSelf->ShouldShowLinks(ev)); 
  2127.     
  2128.         // root frame
  2129.     
  2130.         ODSetStrongSURefProp(ev, su, kODPropRootFrame, kODStrongStorageUnitRef, _fRootFrame->GetStorageUnit(ev)->GetID(ev));
  2131.     
  2132.         // Source Frame (this property is only written if the value is non-NULL)  
  2133.             
  2134.         if (_fSourceFrame)
  2135.         {            
  2136.             ODSetStrongSURefProp(ev, su, kODPropSourceFrame, kODStrongStorageUnitRef, 
  2137.                             _fSourceFrame->GetStorageUnit(ev)->GetID(ev));
  2138.         }
  2139.         else if (ODSUExistsThenFocus(ev, su ,kODPropSourceFrame, kODStrongStorageUnitRef))
  2140.         {
  2141.             su->Remove(ev);
  2142.         }
  2143.         
  2144.         // Annotate the root frame with the window properties
  2145.         ODStorageUnit* frameSU = _fRootFrame->GetStorageUnit(ev);
  2146.         ODSetStrongSURefProp(ev, frameSU, kODPropWindowProperties, kODStrongStorageUnitRef, 
  2147.                         su->GetID(ev));
  2148.     
  2149.         _fIsDirty = kODFalse;
  2150.         
  2151.     SOM_CATCH_ALL
  2152.     SOM_ENDTRY
  2153. }
  2154.  
  2155. //-------------------------------------------------------------------------------------
  2156. // ODWindow: GetID
  2157. //
  2158. // Description
  2159. //-------------------------------------------------------------------------------------
  2160.  
  2161. SOM_Scope ODID  SOMLINK ODWindowGetID(ODWindow *somSelf, Environment *ev)
  2162. {
  2163.     ODWindowData *somThis = ODWindowGetData(somSelf);
  2164.     ODWindowMethodDebug("ODWindow","GetID");
  2165.  
  2166.     return _fID;
  2167. }
  2168.  
  2169. //-------------------------------------------------------------------------------------
  2170. // ODWindow: SetID
  2171. //
  2172. // Description
  2173. //-------------------------------------------------------------------------------------
  2174.  
  2175. SOM_Scope void  SOMLINK ODWindowSetID(ODWindow *somSelf, Environment *ev,
  2176.         ODID windowID)
  2177. {
  2178.     ODWindowData *somThis = ODWindowGetData(somSelf);
  2179.     ODWindowMethodDebug("ODWindow","SetID");
  2180.  
  2181.     _fID = windowID;
  2182. }
  2183.  
  2184. //-------------------------------------------------------------------------------------
  2185. // ODWindow: AcquireStorageUnit
  2186. //
  2187. // Description
  2188. //-------------------------------------------------------------------------------------
  2189.  
  2190. SOM_Scope ODStorageUnit*  SOMLINK ODWindowGetStorageUnit(ODWindow *somSelf, Environment *ev)
  2191. {
  2192.     ODWindowData *somThis = ODWindowGetData(somSelf);
  2193.     ODWindowMethodDebug("ODWindow","GetStorageUnit");
  2194.     
  2195.     SOM_TRY
  2196.     
  2197.         if (_fStorageUnit != kODNULL)
  2198.             _fStorageUnit->Internalize(ev);
  2199.  
  2200.     SOM_CATCH_ALL
  2201.     SOM_ENDTRY
  2202.  
  2203.     return _fStorageUnit;
  2204. }
  2205.  
  2206. //-------------------------------------------------------------------------------------
  2207. // ODWindow: SetStorageUnit
  2208. //
  2209. // Description
  2210. //-------------------------------------------------------------------------------------
  2211.  
  2212. SOM_Scope void  SOMLINK ODWindowSetStorageUnit(ODWindow *somSelf, Environment *ev, ODStorageUnit* su)
  2213. {
  2214.     ODWindowData *somThis = ODWindowGetData(somSelf);
  2215.     ODWindowMethodDebug("ODWindow","SetStorageUnit");
  2216.     
  2217.     SOM_TRY
  2218.  
  2219.         _fStorageUnit = su;
  2220.         su->Acquire(ev);
  2221.         
  2222.         // These below calls are unnecessary because the StdTypIO routines make sure
  2223.         // the appropriate property and value exist. -TÇ
  2224.         /*
  2225.         ODSUAddPropValue(ev, kODPropWindowRect, kODRect);
  2226.         ODSUAddPropValue(ev, kODPropWindowTitle, kODMacIText);
  2227.         ODSUAddPropValue(ev, kODPropWindowProcID, kODSShort);
  2228.         ODSUAddPropValue(ev, kODPropWindowIsVisible, kODBoolean);
  2229.         ODSUAddPropValue(ev, kODPropWindowHasCloseBox, kODBoolean);
  2230.         ODSUAddPropValue(ev, kODPropWindowHasZoomBox, kODBoolean);
  2231.         ODSUAddPropValue(ev, kODPropWindowIsResizable, kODBoolean);
  2232.         ODSUAddPropValue(ev, kODPropWindowIsRootWindow, kODBoolean);
  2233.         ODSUAddPropValue(ev, kODPropWindowIsFloating, kODBoolean);
  2234.         ODSUAddPropValue(ev, kODPropWindowRefCon, kODSLong);
  2235.         ODSUAddPropValue(ev, kODPropRootFrame, kODStrongStorageUnitRef);
  2236.         ODSUAddPropValue(ev, kODPropShouldShowLinks, kODBoolean);
  2237.         */
  2238.         
  2239.         _fIsDirty = kODTrue;
  2240.  
  2241.     SOM_CATCH_ALL
  2242.     SOM_ENDTRY
  2243. }
  2244.  
  2245. //-------------------------------------------------------------------------------------
  2246. // ODWindow: GetDraft
  2247. //
  2248. // Description
  2249. //-------------------------------------------------------------------------------------
  2250.  
  2251. SOM_Scope ODDraft*  SOMLINK ODWindowGetDraft(ODWindow *somSelf, Environment *ev)
  2252. {
  2253.     ODWindowData *somThis = ODWindowGetData(somSelf);
  2254.     ODWindowMethodDebug("ODWindow","GetDraft");
  2255.  
  2256.     return _fDraft;
  2257. }
  2258.  
  2259. //-------------------------------------------------------------------------------------
  2260. // ODWindow: GetWindowPoint
  2261. //
  2262. // Description
  2263. //-------------------------------------------------------------------------------------
  2264.  
  2265. SOM_Scope void SOMLINK ODWindowGetWindowPoint(ODWindow *somSelf, Environment *ev,
  2266.         Point* globalPoint, ODPoint* windowPoint)
  2267. {
  2268.     ODWindowData *somThis = ODWindowGetData(somSelf);
  2269.     ODWindowMethodDebug("ODWindow","GetWindowPoint");
  2270.     
  2271.     Point localCopy = *globalPoint;
  2272.     
  2273.     GrafPtr curPort;
  2274.     GetPort(&curPort);
  2275.     SetPort(_fPlatformWindow);
  2276.     SetOrigin(0,0);
  2277.     GlobalToLocal(&localCopy);
  2278.     SetPort(curPort);
  2279.     *windowPoint = (ODPoint)localCopy;
  2280. }
  2281.